#include "slideshowdlg.h"
#include "ui_slideshowdlg.h"

#include "prelistwid.h"
#include "picanimationwid.h"
#include "protreewidget.h"

SlideShowDlg::SlideShowDlg(QTreeWidgetItem *first_item, QTreeWidgetItem *last_item, QWidget *parent)
    : QDialog(parent), ui(new Ui::SlideShowDlg), _first_item(first_item), _last_item(last_item)
{
    ui->setupUi(this);

    this->setWindowFlags(Qt::Dialog | Qt::FramelessWindowHint);

    // 连接关闭按钮
    ui->closeBtn->SetIcons(":/icon/closeshow.png", ":/icon/closeshow_hover.png", ":/icon/closeshow_press.png");
    ui->closeBtn->setStyleSheet("QPushButton { border: 0px; }");
    connect(ui->closeBtn, &QPushButton::clicked, this, &SlideShowDlg::close);

    // 连接向后查看按钮 //连接向前查看按钮
    ui->slidepreBtn->SetIcons(":/icon/previous.png", ":/icon/previous_hover.png", ":/icon/previous_press.png");
    ui->slidenextBtn->SetIcons(":/icon/next.png", ":/icon/next_hover.png", ":/icon/next_press.png");
    // 边框就不要了。再去 ui 文件，把 QPushButton 所在的 QWidget 的 Margin 的值设置为 0，就可以看到的是一个圆形的按钮了哦
    ui->slidepreBtn->setStyleSheet("QPushButton { border: 0px; }");
    ui->slidenextBtn->setStyleSheet("QPushButton { border: 0px; }");
    connect(ui->slidenextBtn, &QPushButton::clicked, this, &SlideShowDlg::SlotSlideNext);
    connect(ui->slidepreBtn, &QPushButton::clicked, this, &SlideShowDlg::SlotSlidePre);

    // 连接动画和按钮显示状态
    ui->playBtn->SetIcons(":/icon/play.png", ":/icon/play_hover.png", ":/icon/play_press.png",
                          ":/icon/pause.png", ":/icon/pause_hover.png", ":/icon/pause_press.png");
    ui->playBtn->setStyleSheet("QPushButton { border: 0px; }");
    connect(ui->picAnimation, &PicAnimationWid::SigStart, ui->playBtn, &PicStateBtn::SlotStart);
    connect(ui->picAnimation, &PicAnimationWid::SigStop, ui->playBtn, &PicStateBtn::SlotStop);

    // 连接 ui->preListWidget 和 ui->picAnimation
    auto *prelistWid = dynamic_cast<PreListWid *>(ui->preListWidget);
    connect(ui->picAnimation, &PicAnimationWid::SigUpPreList, prelistWid, &PreListWid::SlotUpPreList);
    connect(ui->picAnimation, &PicAnimationWid::SigSelectItem, prelistWid, &PreListWid::SlotUpSelect);

    // 点击 prelistWid 预览的图片后，轮播图显示的也是对应的图片
    connect(prelistWid, &PreListWid::SigUpSelectShow, ui->picAnimation, &PicAnimationWid::SlotUpSelectShow);

    // 按钮控制启动动画和停止动画
    connect(ui->playBtn, &PicStateBtn::clicked, ui->picAnimation, &PicAnimationWid::SlotStartOrStop);

    auto * _protree_widget = dynamic_cast<ProTreeWidget*>(parent);
    // 连接音乐启动信号
    connect(ui->picAnimation, &PicAnimationWid::SigStartMusic, _protree_widget, &ProTreeWidget::SlotStartMusic);
    // 连接音乐关闭信号
    connect(ui->picAnimation,&PicAnimationWid::SigStopMusic, _protree_widget, &ProTreeWidget::SlotStopMusic);


    ui->picAnimation->SetPixmap(_first_item);
    ui->picAnimation->Start();
}

SlideShowDlg::~SlideShowDlg()
{
    delete ui;
}

void SlideShowDlg::SlotSlideNext()
{
    ui->picAnimation->SlideNext();
}
void SlideShowDlg::SlotSlidePre()
{
    ui->picAnimation->SlidePre();
}
